public class Leet21 {
    public static void main(String[] args) {

    }
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode now;
        ListNode re;
        if (l1==null&&l2==null)
            return null;
        if (l1==null){
            return l2;
        }else if (l2==null){
            return l1;
        }else if (l1.val<=l2.val) {
            now = l1;
            l1 = l1.next;
        } else {
            now = l2;
            l2 = l2.next;
        }
        re = now;
        while (true){
            if (l1==null){
                now.next = l2;
                break;
            }else if (l2==null){
                now.next = l1;
                break;
            }else if (l1.val<=l2.val){
                now.next=l1;
                l1 = l1.next;
            }else{
                now.next = l2;
                l2 = l2.next;
            }
            now = now.next;
        }
        return re;
    }
}

class ListNode {
     int val;
     ListNode next;
     ListNode() {}
     ListNode(int val) { this.val = val; }
     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }

